/** @namespace app.model.Message */
module.exports = app => {
  const {STRING, TINYINT} = app.Sequelize;

  const Message = app.model.define('message', {
    title: {type: STRING(30)},
    content: {type: STRING},
    type: {type: TINYINT(1).UNSIGNED, allowNull: false, defaultValue: 0},
  }, {
    updatedAt: false,
    scopes: {
      message: {where: {type: 0}},
      notify: {where: {type: 1}},
    },
  });

  Message.textMessage = async (data) => {
    data.type = 0;
    await app.model.Message.create(data);
  };

  Message.atUserMessage = async (data) => {
    data.type = 1;
    await app.model.Message.create(data);
  };

  return Message;
};